package com.itheima.tlais_web_management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlais_web_management.mapper.MovieMapper;
import com.itheima.tlais_web_management.pojo.Movie;
import com.itheima.tlais_web_management.pojo.PageBean;
import com.itheima.tlais_web_management.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MovieServiceImpl implements MovieService {

    @Autowired
    private MovieMapper movieMapper;

    @Override
    public PageBean list(String name, Integer page, Integer pageSize) {
        //分页插件
        //查第几页，每页展示几条
        Page<Object> page1 = PageHelper.startPage(page, pageSize);
        //根据名字查询数据
        List<Movie> movieList = movieMapper.list(name);
        //将查询到的数据集合转为page对象
        Page<Movie> moviePage = (Page<Movie>) movieList;

        //根据 page 集合对象得到一些数据
        //总记录 toyal，当前这一页的数据 Result
        PageBean pageBean = new PageBean(moviePage.getTotal(),moviePage.getResult());

        return pageBean;

    }

    @Override
    public void deletebyids(List<Integer> ids) {
        movieMapper.deletebuids(ids);
    }
}
